package com.xushu.lessons.vip;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration		// spring.xml
@ComponentScan		// <component-scan  >
public class MainStart {
	public static void main(String[] args) {

		// spring容器  ioc容器  spring上下文    创建bean   依赖注入
		AnnotationConfigApplicationContext context =
				new AnnotationConfigApplicationContext(MainStart.class);

		System.out.println("容器已加载");
		System.out.println(context.getBean("userService"));

/*
		// getBean 获取  ---  创建----> 先拿到BeanDefinition
		XushuService xushuService = (XushuService) ctx.getBean("xushuService");
	 	// new XushuService();     依赖注入
		System.out.println(xushuService);*//**//*

		// 手动完成整个容器加载

		DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();


		// 读取配置
		AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(beanFactory);
		reader.register(MainStart.class);


		AnnotatedGenericBeanDefinition beanDefinition= (AnnotatedGenericBeanDefinition) beanFactory.getBeanDefinition("mainStart");
		AnnotationMetadata metadata = beanDefinition.getMetadata();
		if(metadata.hasAnnotation(ComponentScan.class.getName())){
			Map<String, Object> annotationAttributes = metadata.getAnnotationAttributes(ComponentScan.class.getName());
			// Utils if basepackages == ""
			//    当前配置类的包当做扫描包
		}


		// 扫描
		ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(beanFactory);
		scanner.scan("com.xushu.vip");

		beanFactory.preInstantiateSingletons();*/





	}
}
